﻿log("Running Taobao Searcher 2  ...  searchTaobao2.js")

// current position
isIndexPage = function ()
{
    return location.href.search("mosaic.re.taobao.com/search?") !== -1
    && location.href.search("keyword=") === -1;
}
isSearchPage = function ()
{
    return location.href.search("mosaic.re.taobao.com/search?") !== -1
    && location.href.search("keyword=") !== -1;
}

// index
getSearchEdit = function ()
{
    return q;
}
getSubmitButton = function ()
{
    return document.querySelector("#J_searchForm > input.submit");
}

// search methods
priceSetted = null;
getSortMethod = null;
locationSetted = null;


// items 
getTops = function ()
{
    return  document.querySelectorAll("div.item");
}
getA = function (_top)
{
    return _top.querySelector(".info a.title");
}
parseTop = function(_top)
{
    var img = _top.querySelector(".imgContainer img");
    var a = _top.querySelector(".info a.title");
    var id = null;
    var price = _top.querySelector(".info .price a");
    var shop = _top.querySelector(".shopName .shopNick");
    var _location = null;

    return {
        extra: {
            top: _top
        },
        keyword: arg.itemName,
        title: a ? fixString(a.textContent) : "",
        id: "",
        price: price ? fixPrice(fixString(price.textContent)) : "",
        shop: shop ? fixString(shop.textContent) : "",
        link: a ? a.href : "",
        imgsrc: https2http(img ? ((img.src && img.src) != "" ? img.src : ("http:" + img.getAttribute("data-src"))) : ""),
        location: ""
    };
}

nextPageButton = function ()
{
    return document.querySelector("#J_waterfallPagination > div > div > a.page-next.iconfont");
}